package com.komodo.island.gdx;

import java.text.DecimalFormat;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

public class Art {

	
	public static Texture tulisanTexture;
	
	static SpriteBatch batch;
	static TextureRegion huruf[];
	static TextureRegion angka[];
	static TextureRegion hurufB[];
	public static DecimalFormat decimal2 = new DecimalFormat("#.##");

	static {
	
		tulisanTexture = new Texture(Gdx.files.internal("tulisan1.png"));

		batch = new SpriteBatch();
		huruf = new TextureRegion[27];
		hurufB = new TextureRegion[27];

		angka = new TextureRegion[13];

		for (int i = 0; i < 26; i++) {
			huruf[i] = new TextureRegion(tulisanTexture, i * 32,
					0, 32, 32);
		}
		for (int i = 0; i < 13; i++) {
			angka[i] = new TextureRegion(tulisanTexture, i * 32, 64, 32, 32);

		}
		for (int i = 0; i < 26; i++) {
			hurufB[i] = new TextureRegion(tulisanTexture, i * 32,32, 32, 32);

		}

	}

	public static void drawString(String text, int x, int y) {

		batch.begin();
		int index;
		for (int i = 0; i < text.length(); i++) {
			index = (Integer.valueOf(text.charAt(i)));
			if (index >= 97 && index <= 123) {
				batch.draw(huruf[index - 97], x, y, 32, 32);
				x += 20;
			} else if (index >= 48 && index <= 57) {
				batch.draw(angka[index - 48], x, y, 32, 32);
				x += 20;
			} else if (index >= 65 && index <= 91) {
				batch.draw(hurufB[index - 65], x, y, 32, 32);
				x += 20;
			} else if (index == 58) {
				// :
				batch.draw(angka[10], x, y, 32, 32);
				x += 20;
			} else if (index == 46 || index == 44) {
				// .
				batch.draw(angka[11], x, y, 32, 32);
				x += 10;
			} else if (index == 45 ) {
				// -
				batch.draw(angka[12], x, y, 32, 32);
				x += 20;
			} else {
				x += 10;
			}

		}
		batch.end();
	}

	public static void drawString(SpriteBatch batch, String text, int x, int y) {

		batch.begin();
		int index;
		for (int i = 0; i < text.length(); i++) {
			index = (Integer.valueOf(text.charAt(i)));
			if (index >= 97 && index <= 123) {
				batch.draw(huruf[index - 97], x, y, 32, 32);
				x += 20;
			} else if (index >= 48 && index <= 57) {
				batch.draw(angka[index - 48], x, y, 32, 32);
				x += 20;
			} else if (index >= 65 && index <= 91) {
				batch.draw(hurufB[index - 65], x, y, 32, 32);
				x += 20;
			} else if (index == 58) {
				// :
				batch.draw(angka[10], x, y, 32, 32);
				x += 20;
			} else if (index == 46 || index == 44) {
				// .
				batch.draw(angka[11], x, y, 32, 32);
				x += 10;
			}  else if (index == 45 ) {
				// -
				batch.draw(angka[12], x, y, 32, 32);
				x += 20;
			}else {
				x += 10;
			}

		}
		batch.end();
	}

}
